package com.it2297.controller;

import java.awt.Color;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

import com.it2297.model.Bid;
import com.it2297.model.UsedItem;
import com.it2297.model.UsedItem.Type;
import com.it2297.view.DonationReportView;

public class DonationReportController
{
	private DonationReportView reportView;

	public DonationReportController(DonationReportView reportView)
	{
		this.reportView = reportView;

		reportView.setTotalItemDonated(UsedItem.getTotalItemDonated());
		reportView.setTotalBids(Bid.getTotalBids());
		reportView.setTotalUniqueDonor(UsedItem.getTotalUniqueDonor());
		reportView.setTotalUniqueBidder(Bid.getTotalUniqueBidder());
		reportView.setTotalApproved(UsedItem.getTotalApproved());
		reportView.setTotalPending(UsedItem.getTotalPending());
		reportView.setTotalRejected(UsedItem.getTotalRejected());
		reportView.setTotalEnded(UsedItem.getTotalEnded());

		DefaultPieDataset dpd = new DefaultPieDataset();
		for (Type type : Type.values())
		{
			dpd.setValue(type.name(), UsedItem.getTotalItemType(type));
		}
		JFreeChart chart = ChartFactory.createPieChart(null, dpd, false, true, false);
		chart.getPlot().setBackgroundPaint(new Color(237, 237, 237));
		chart.setBackgroundPaint(new Color(237, 237, 237));
		chart.getPlot().setOutlineVisible(false);

		reportView.setChart(chart);

		reportView.setTopBidder(Bid.getTopBidder());
		reportView.setTopDonor(UsedItem.getTopDonor());
		reportView.setMostPopularBid(Bid.getMostPopularBid());
		reportView.setRecentWonBid(Bid.getRecentWonBid());

	}
}
